package com.itheima.d4_synchronized_code;

public class Ticket implements Runnable {
    private int  ticker = 100;
    private Object object = new Object();
    @Override
    public void run() {
        while (true){
            synchronized(object){
                if (ticker <=0){
                    break;
                }else {
                    ticker --;
                    System.out.println(Thread.currentThread().getName()+ "窗口剩余票数"+ticker);
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
